package org.example;

import java.util.ArrayList;
import java.util.List;

public class BookShelf implements Aggregate{
    private List<Book> books;
    private int index=0;

    //初始化集合
    public BookShelf() {
        books=new ArrayList<>();
    }

    //提取元素
    public Book getBootAt(int index){
        Book book = books.get(index);
        index++;
        return book;
    }

    //往集合中添加元素
    public void appendBook(Book book){
        books.add(book);
    }

    //获取元素长度
    public int getLenght(){
        return books.size();
    }
    @Override
    public Interator interator() {
        return new BooklShelfIterator(this);
    }
}
